package com.hepinghospital.user.ui.fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseFragment;

import org.jetbrains.annotations.NotNull;

import butterknife.BindView;


/**
 *
 * @author HP
 * @date 2020/2/25
 */

public class MyDiagnoseOrderFragment extends BaseFragment {

    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;

    private int page;

    @Override
    protected void initView() {
        mViewPager.setAdapter(new CloudFragmentAdapter(getActivity(), getChildFragmentManager()));
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        mViewPager.setCurrentItem(page);
        mTabLayout.getTabAt(page).select();
    }

    public static MyDiagnoseOrderFragment newInstance(int type, int page) {
        Bundle args = new Bundle();
        args.putInt("type", type);
        args.putInt("page", page);
        MyDiagnoseOrderFragment fragment = new MyDiagnoseOrderFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected void initData() {
        int type = getArguments().getInt("type");
        page = getArguments().getInt("page");
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_my_cloud;
    }

    static class CloudFragmentAdapter extends FragmentPagerAdapter {
        private static final int PAGE_COUNT = 6;

        CloudFragmentAdapter(Context context, FragmentManager fm) {
            super(fm);
        }

        @NotNull
        @Override
        public Fragment getItem(int position) {
            String type;
            switch (position) {
                case 0:
                    type = "0";
                    break;
                case 1:
                    type = "1";
                    break;
                case 2:
                    type = "3";
                    break;
                case 3:
                    type = "4";
                    break;
                case 4:
                    type = "5";
                    break;
                case 5:
                    type = "7";
                    break;
                default:
                    type = "6";
                    break;
            }
            return PicListFragment.newInstance(type);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "全部";
                case 1:
                    return "待支付";
                case 2:
                    return "进行中";
                case 3:
                    return "待评价";
                case 4:
                    return "已取消";
                case 5:
                    return "已结束";
                default:
                    return "已取消";
            }
        }
    }
}
